date=`date +%Y%m%d`
user_home=/home/zyb
dist_dir=${r'${user_home}'}/apps/update/dist
distHistory_dir=${r'${user_home}'}/apps/update/distHistory
backup_dir=${r'${user_home}'}/apps/backup/${r'${date}'}
update_dir=${r'${user_home}'}/apps/update/${r'${date}'}
app_home=${r'${user_home}'}/apps/ems

if [ ! -d $distHistory_dir ]; then
        mkdir $distHistory_dir
        echo "mkdir ${r'${distHistory_dir}'} done"
fi

if [ ! -d $backup_dir ]; then
        mkdir $backup_dir
        echo "mkdir ${r'${backup_dir}'} done"
fi

if [ ! -d $update_dir ]; then
        mkdir $update_dir
        echo "mkdir ${r'${update_dir}'} done"
fi

echo "复制本次修改文件到${r'${update_dir}'}目录"
cp ${r'${dist_dir}'}/* ${r'${update_dir}'}/

echo "备份被修改文件到${r'${backup_dir}'}目录"
<#list backupList as backup>
    cp -p ${r'${app_home}'}/${backup.path} ${r'${backup_dir}'}/${backup.fileName}
</#list>

echo "备份完成"
read -p "输入任意字符，开始覆盖更新文件" input

<#list updateList as update>
    cp -p ${r'${update_dir}'}/${update.fileName} ${r'${app_home}'}/${update.path}
</#list>

echo "更新完成"
echo "打包并移动脚本及dist目录完成"

tar -cf ${r'${data}'}.tar ./dist ./ht_deploy.sh
mv ${r'${date}'}.tar ${r'${distHistory_dir}'}
rm -rf ./dist
rm -- "$0"

exit 0
